package org.seoul.gtugs.client.ui;

import java.util.List;

import org.seoul.gtugs.shared.PhotoEntity;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Grid;

public class MobilePhotoListUI extends Composite implements PhotoListDisplay {

	private static MobilePhotoListUIUiBinder uiBinder = GWT
			.create(MobilePhotoListUIUiBinder.class);
	@UiField Grid photoGrid;

	interface MobilePhotoListUIUiBinder extends
			UiBinder<Widget, MobilePhotoListUI> {
	}

	public MobilePhotoListUI() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public MobilePhotoListUI(String firstName) {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setData(List<PhotoEntity> data) {
		if(data == null || data.size() < 1)	return;
		int nSize = data.size();
		
// "photoGrid.resize(2, 2);
		if(nSize < 1)
			photoGrid.resize(1, 1);
		else
			photoGrid.resize(nSize, 3);
		

		
		for(int k=0; k<nSize;k++){
			int rowIndex = k / 3;
			int colIndex = k % 3;
			
			PhotoEntity photo = data.get(k);
			photoGrid.setWidget(rowIndex, colIndex, new Image(photo.getServingUrl()+"=s100"));
		}
		
	}
	public Widget asWidget(){
		return this;
	}

	@Override
	public HasClickHandlers getLinkButton() {
		// TODO Auto-generated method stub
		return null;
	}

}
